package com.eastfair.venueservice.service.impl;

import com.eastfair.common.api.TransactionFeign;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.pay.dto.TransactionDTO;
import com.eastfair.pay.vo.TransactionVO;
import com.eastfair.venueservice.service.VenueManageTransactionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 综合服务 交易流水 service.
 *
 * @author dqq
 * @date 2023 /2/17
 */
@Slf4j
@Service
public class VenueManageTransactionServiceImpl implements VenueManageTransactionService {

    @Resource
    private TransactionFeign transactionFeign;

    @Override
    public boolean save(TransactionDTO transactionDTO) {
        log.info("save - 保存交易记录, transactionDTO={}", transactionDTO);
        R result = transactionFeign.save(transactionDTO);
        log.info("save - 保存交易记录完成, result={}", result);
        if (!result.getIsSuccess()) {
            log.error("调用保存交易记录接口失败, result={}", result);
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return true;
    }

    @Override
    public boolean update(TransactionDTO transactionDTO) {
        log.info("update - 更新交易记录, transactionDTO={}", transactionDTO);
        R result = transactionFeign.update(transactionDTO);
        log.info("update - 更新交易记录完成, result={}", result);
        if (!result.getIsSuccess()) {
            log.error("调用更新交易记录接口失败, result={}", result);
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return true;
    }

    @Override
    public List<TransactionVO> getTransactions(TransactionDTO transactionDTO) {
        log.info("getTransactions - 通过查询条件获取交易记录, transactionDTO={}", transactionDTO);
        R<List<TransactionVO>> result = transactionFeign.getTransactions(transactionDTO);
        log.info("getTransactions - 通过查询条件获取交易记录完成, result={}", result);
        if (!result.getIsSuccess()) {
            log.error("调用通过查询条件获取交易记录接口失败, result={}", result);
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }
}